var minPlayers = 3;

function init() {
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}

function setup(eim, leaderid) {
	em.setProperty("state", "1");
	em.setProperty("leader", "true");
	var eim = em.newInstance("HenesysPQ" + leaderid);
	em.setProperty("stage", "0");
	var map = eim.setInstanceMap(910010000);
	map.resetFully();
	map.setSpawns(false);
	eim.startEventTimer(600000); //10 分
	return eim;
}

function playerEntry(eim, player) {
	var map = eim.getMapInstance(0);
	player.changeMap(map, map.getPortal(0));
}

function playerRevive(eim, player) {}

function scheduledTimeout(eim) {
	end(eim);
}

function changedMap(eim, player, mapid) {
	if (mapid != 910010000) {
		eim.unregisterPlayer(player);

		if (eim.disposeIfPlayerBelow(0, 0)) {
			em.setProperty("state", "0");
			em.setProperty("leader", "true");
		}
	}
}

function playerDisconnected(eim, player) {
	return 0;
}

function monsterValue(eim, mobId) {
	if (mobId == 9300061) {
		eim.broadcastPlayerMsg(5, "月兔被殺死了 嗚嗚");
		end(eim);
	}
	return 1;
}

function playerExit(eim, player) {
	eim.unregisterPlayer(player);

	if (eim.disposeIfPlayerBelow(0, 0)) {
		em.setProperty("state", "0");
		em.setProperty("leader", "true");
	}
}

function end(eim) {
	eim.disposeIfPlayerBelow(100, 910010300);
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}

function clearPQ(eim) {
	end(eim);
}

function allMonstersDead(eim) {}

function leftParty(eim, player) {
	// If only 2 players are left, uncompletable:
	var party = eim.getPlayers();
	if (party.size() < minPlayers) {
		end(eim);
	} else
		playerExit(eim, player);
}
function disbandParty(eim) {
	end(eim);
}
function playerDead(eim, player) {}
function cancelSchedule() {}
